<include file="Public:header" />
<div class="subnav">
  <div class="explain-col" >
    <form name="addForm" id="addForm" method="POST" action="__CONTROLLER__/add">
      <table class="add-table">
        <tr>
          <td width="240">
            合作人：<input type="text" name="data[name]" id="name" size="20"  value="{$Think.get.name}" class="input-text" placeholder="请输入合作人名称" />
          </td>
          <td width="140">
            排序：<input type="text" name="data[sort]" id="sort" size="6"  value="{$Think.get.sort}" class="input-text" placeholder="排序" style="width: 60px;" />
          </td>
          <td width="340">
            备注：<input type="text" name="data[remark]" id="remark" size="6"  value="{$Think.get.remark}" class="input-text" placeholder="备注" style="width: 260px;" />
          </td>

          <td>
            <input type="submit" value=" 添加合作人 " id="add-button" class="button" style=" position: relative; top:50%; left:50%;" />
          </td>
        </tr>

      </table>
    </form>
  </div>
</div>
<!--subnav-->

<div class="pad-lr-10">
    <div class="table-list">
    <form name="listForm" id="listForm" action="" method="GET">
      <table width="100%" cellspacing="0">
        <thead>
          <tr>
            <th align="center" width="60">选择</th>
            <th align="center" width="120">合作人名称</th>
            <th align="center" width="80">排序</th>
            <th align="center" width="120">备注</th>
            <th align="center" width="80">状态</th>
            <th align="center" width="120">更新时间</th>
            <th align="center" width="120">添加时间</th>
          </tr>
        </thead>
        <tbody id="list">
          <volist name="list" id="vo">
            <tr  id="{$vo.id}" value="{$vo.id}" class="{$vo.class}">
              <td align="center" ><input type="checkbox" name="idArr[]" value="{$vo.id}"></td>
              <td align="center" edit="0" fd="name">{$vo.name}</td>
              <td align="center" edit="0" fd="sort">{$vo.sort}</td>
              <td align="center" edit="0" fd="remark">{$vo.remark}</td>
              <td align="center">{$vo.status|statusArr}</td>
              <td align="center">{$vo.update_time|date='Y-m-d H:i:s',###}</td>
              <td align="center">{$vo.create_time|date='Y-m-d H:i:s',###}</td>

            </tr>
          </volist>
          <empty name="list">
            <tr>
              <td colspan="5" align="center">请添加电话分组</td>
            </tr>
          </empty>
        </tbody>
      </table>
      <div class="btn">
        <div id="pages">{$page}</div>
        <input name="submit" id="checkall" type="button" class="button" value="全选/反选">
        <eq name="Think.session.user_id" value="1">
          <input name="submit" type="button" class="button" value="删除所选"  onclick="return deleteConfirm();">
        </eq>
      </div>
      </form>
    </div>
</div>
</body>
</html>
<script type="text/javascript">
$(document).ready(function(e) {
    $('#addForm').ajaxForm({
      beforeSubmit:  checkForm,
      success:       complete,
      dataType: 'json'
  });

  //全反选
  $("#checkall").click(function(){
    $("input[name=idArr[]]").each(function(){
      if(this.checked == false)
        this.checked = true;
      else
          this.checked = false;
    });
  });

  //快捷改变操作排序dblclick
  $("tbody>tr>td[fd]").click(function(){
      var inval = $(this).html();
      var infd = $(this).attr("fd");
      var inid =  $(this).parents("tr").attr("id");
      var size = 8;
      if(infd=='remark'){
        size = 18;
      }
      if($(this).attr('edit')==0){
        $(this).attr('edit','1').html("<input class='input' size='"+size+"' id='edit_"+infd+"_"+inid+"' value='"+inval+"' />").find("input").select();
      }

      $("#edit_"+infd+"_"+inid).focus().bind("blur",function(){
          var editval = $(this).val();
          if(inval!=editval){
              $.post("__CONTROLLER__/change",{id:inid,fd:infd,value:editval});
          }
          $(this).parents("td").html(editval).attr('edit','0');
      })
  });

});

function checkForm(){
  var name = $("#name").val();
  if( name=='' ){
    art.dialog({id:'TNCICC',content: '请输入合作人名称',time: 1,icon:'warning'});
    $('#name').focus();
    return false;
  }

  return true;
}

function complete(data){
  if(data.status==1){
    $("#add-button").attr('value',' 添加成功 ');
    $("#add-button").attr('disabled',true);
    setTimeout(function(){
      $('#addForm')[0].reset();
      $("#add-button").attr('disabled',false);
      location.reload();
    },1500);
  }else{
    art.dialog({id:'TNCICC',content: data.info,time: 1,icon:'warning'});
  }
}

function deleteConfirm(){
  window.top.art.dialog({
    content: '确定删除所选数据？',
    ok: function () {
      del();
      return true;
    },
    cancelVal: '取消',
    cancel: true
  });
}

function del(){
  var idArr = Array();
  var i = 0;
  var id;
  $("input[name='idArr[]']").each(function(){
    if(this.checked == true){
      idArr[i] = $(this).val();
      i++;
    }
  });
  jQuery.post('__CONTROLLER__/del',encodeURI('id='+idArr),success,'json');
  function success(data){
    if(data.status==1){
      window.top.art.dialog({id:'TNCICC',content: data.info,time: 2,icon:'succeed'});
      setTimeout(function(){window.location.reload();closeWin(1500);},2000);
    }else{
      window.top.art.dialog({id:'TNCICC',content: data.info,time: 2,icon:'warning'});
    }

  }
}

</script>